package  
{
	import flare.basic.*;
	import flare.core.*;
	import flare.primitives.*;
	import flare.system.*;
	import flash.display.*;
	import flash.events.*;
	import flash.utils.*;
	import particles.*;
	
	[SWF(frameRate = 120, backgroundColor = 0x808080, width = 800, height = 600 )]
	/**
	 * ...
	 * @author Ariel Nehmad
	 */
	public class Test10_Custom_Particles extends Sprite 
	{
		private var scene:Scene3D;
		private var emiter:ParticleEmiter3D;
		private var texture:Texture3D;
		private var cube:Cube;
		
		public function Test10_Custom_Particles() 
		{
			addChild( new Stats() );
			
			scene = new Viewer3D( this );			
			scene.camera.setPosition( 0, 50, -100 );
			scene.camera.lookAt( 0, 0, 0 );
			
			cube = new Cube();
			cube.parent = scene;
			
			texture = scene.addTextureFromFile( "Cross_0005.jpg" );
			
			emiter = new ParticleEmiter3D( "emiter", texture, new CustomParticle() );
			emiter.useGlobalSpace = true;
			emiter.setColors( [ 0x0000ff, 0xff0000, 0xffff00 ], [1, 1, 0] );
			emiter.particlesPerFrame = 5;
			emiter.particlesLife = 100;
			emiter.addParticles( 500 );
			emiter.parent = cube;
			// particles and objects with alpha, usually need to be render
			// after the other 3d objects because they don't write to z-buffer.
			emiter.layer = 10;
			
			scene.addEventListener( Scene3D.UPDATE_EVENT, updateEvent );
		}
		
		private function updateEvent(e:Event):void 
		{
			cube.x = Math.cos( getTimer() / 1000 ) * 50;
			cube.z = Math.sin( getTimer() / 1000 ) * 50;
			
			if ( Input3D.keyHit( Input3D.SPACE ) ) emiter.useGlobalSpace = !emiter.useGlobalSpace;
		}
	}
}